function compose(middleware) {
    if (!Array.isArray(middleware)) {
        return;
    }
    for (const fn of middleware) {
        if (typeof fn !== 'function') throw new TypeError('middleware must be a function');
    }
    return function (context, next) {
        let index = -1;
        return dispatch(0);

        function dispatch(i) {
            if (i <= index) return Promise.reject(new Error('next() called multiple times'))
            index = i;
            let fn = middleware(i);
            if (i == middleware.length) fn = next;
            if (!fn) return Promise.resolve();
            try {
                return Promise.reslove(fn(context, function next() {
                    return dispatch(i + 1);
                }))
            } catch (error) {
                return Promise.reject(error);
            }
        }
    }
}
let i = 0;

function fc(name, next) {
    if (i > 10)
        return;
    next();
    console.log('name is :' + i + name)
    return fc()
}
fc('a', function next() {
    i++
    console.log(i)


})

function Single(name) {
    this.name = name;
    this, instance = null;
}
Single.getInstance = function (name) {
    if (!this.instance) {
        this.instance = new Single(name);
    }
    return this.instance;
}